﻿Imports SIGI.Common.BE
Imports System.Data.SqlClient
Imports System.Configuration

Public Class PermissionDAC

#Region "<< -Search- >>"
    Public Shared Function Search() As List(Of PermissionBE)
        Dim wSqlConn As SqlConnection = Nothing
        Dim wSqlCmd As SqlCommand = Nothing
        Dim wReader As SqlDataReader = Nothing
        Dim wConnStr As String = String.Empty

        Dim wPermissionBEList As List(Of PermissionBE) = Nothing
        Dim wPermissionBE As PermissionBE = Nothing

        Try
            'Obtengo la cadena de conexión
            wConnStr = ConfigurationManager.ConnectionStrings("connString").ConnectionString
            'Creo la conexión a la BD
            wSqlConn = New SqlConnection(wConnStr)
            'Creo el comando
            wSqlCmd = New SqlCommand()
            wSqlCmd.Connection = wSqlConn
            wSqlCmd.CommandType = CommandType.StoredProcedure
            wSqlCmd.CommandText = "Permisos_s"

            wSqlConn.Open()

            wReader = wSqlCmd.ExecuteReader()
            wPermissionBEList = New List(Of PermissionBE)
            While wReader.Read()
                wPermissionBE = New PermissionBE
                wPermissionBE.Id = Convert.ToInt32(wReader("ID_Permiso"))
                wPermissionBE.Description = Convert.ToString(wReader("Descripcion"))

                wPermissionBEList.Add(wPermissionBE)
            End While

            wSqlConn.Close()
        Catch ex As Exception
            Throw ex
        End Try

        Return wPermissionBEList
    End Function
#End Region

End Class
